package com.agua.enturno.vista.paginas.login;

import org.apache.wicket.authroles.authentication.panel.SignInPanel;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

public class LoginPanel extends SignInPanel {

	private static final long serialVersionUID = 1L;
	private String registerName;
	private String registerEmail;
	private String registerPassword;

	public LoginPanel(String id) {
		super(id);
		
		@SuppressWarnings("rawtypes")
		Form registrationForm = new Form("registration-form") {
			private static final long serialVersionUID = 1L;
		
			@Override
			protected void onSubmit() {
			
				PageParameters pageParameters = new PageParameters();
				pageParameters.add("name", registerName != null ? registerName : "");
				pageParameters.add("email", registerEmail != null ? registerEmail : "");
				pageParameters.add("password", registerPassword != null ? registerPassword : "");
								
				setResponsePage(new RegistrationPage(pageParameters));
			}
		};
		
		registrationForm.add(new TextField<String>("register-name", new PropertyModel<String>(this, "registerName")));
		registrationForm.add(new TextField<String>("register-email", new PropertyModel<String>(this, "registerEmail")));
		registrationForm.add(new PasswordTextField("register-password", new PropertyModel<String>(this, "registerPassword")).setRequired(false));
		add(registrationForm);
	}
	
}
